package com.easyjob.controller;

import com.easyjob.annotation.GlobalInterceptor;
import com.easyjob.annotation.VerifyParam;
import com.easyjob.entity.enums.PermissionCodeEnum;
import com.easyjob.entity.po.Chapter;
import com.easyjob.entity.po.QuestionBank;
import com.easyjob.entity.query.ChapterQuery;
import com.easyjob.entity.query.QuestionBankQuery;
import com.easyjob.entity.vo.ResponseVO;
import com.easyjob.service.ChapterService;
import com.easyjob.service.QuestionBankService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/chapter")
public class ChapterController extends ABaseController{

    @Resource
    private ChapterService chapterService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadAllChapter")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_LIST)
    public ResponseVO loadDataList(ChapterQuery query) {
        return getSuccessResponseVO(chapterService.findListByPage(query));
    }

    @RequestMapping("/saveChapter")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO saveCategory(Chapter chapter) {
        chapterService.saveChapter(chapter);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/delChapter")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO delCategory(@VerifyParam(required = true) Integer chapterId) {
        chapterService.deleteChapterByChapterId(chapterId);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/changeSort")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.CATEOGRY_EDIT)
    public ResponseVO changeSort(@VerifyParam(required = true) String chapterIds) {
        chapterService.changeSort(chapterIds);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/loadAllChapter4Select")
    @GlobalInterceptor
    public ResponseVO loadAllChapter(Integer categoryId) {
        return getSuccessResponseVO(chapterService.loadAllChapterByType(categoryId));
    }
}
